import 'package:flutter/material.dart';

///
/// 页面或者卡片中，单列的展示 Key-Value 文本数据
///
class QPairInfoTable extends StatelessWidget {
  final List<PairInfoModel> dataList; // 数据
  final double titleWidth; // 标题宽度
  final double itemSpace; // item 上下间距

  const QPairInfoTable({
    Key? key,
    required this.dataList,
    this.titleWidth = 110,
    this.itemSpace = 4,
  }) : super(key: key);

  _item(index) {
    PairInfoModel model = dataList[index];
    return Container(
      padding: EdgeInsets.only(top: itemSpace),
      child: Row(
        children: [
          SizedBox(
            width: titleWidth,
            child: Text(model.title),
          ),
          Expanded(child: Text(model.content)),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    var table = ListView.builder(
      physics: const NeverScrollableScrollPhysics(),
      itemCount: dataList.length,
      itemBuilder: (ctx, index) {
        return _item(index);
      },
    );
    double height = (itemSpace + 22) * dataList.length;

    return SizedBox(
      height: height,
      child: table,
    );
  }
}

class PairInfoModel {
  final String title;
  final String content;

  PairInfoModel({this.title = "标题", this.content = "内容"});
}
